#include "sc.h"

extern int SC_INPUT_BUFSIZE, SC_OUTPUT_BUFSIZE;

NeighbourhoodToPixelOp()
interpolate(in stream unsigned char i[-1..0][-1..0],
            out stream unsigned char *o)
{
  *o = i[-1][0]*0.24 + i[-1][-1]*0.24 + i[0][-1]*0.24 + i[0][0]*0.24;
}

NeighbourhoodToPixelOp()
average(in stream unsigned char i[-1..1][-1..1],
        out stream unsigned char *o)
{
  int x, y, temp;
  
  temp = 0;
  for (y=-1; y < 2; y++)
    for (x=-1; x < 2; x=x+2)
      temp = temp + i[y][x];
      
  *o = temp/9;
}

PixelToPixelOp()
subtract(in stream unsigned char *i1,
         in stream unsigned char *i2,        
         out stream unsigned char *o)
{
  *o = 128 + (*i1-*i2)/2;
}

int main(int argc, char **argv)
{
  int i=0, j, k, maxval, maxc, dummy;
  STREAM a, b, c, d, e, f, g;

  scInit(argc, argv);

  capture(&a);

  average(&a, &b);
  for (i=0; i < 25; i++)
    average(&b, &b);

  subtract(&a, &b, &a);
  _finalize(&b);

  display(&a);
  _block(&a);

  return scExit();
}
